﻿$startdate=date
function filesize ([string]$filepath)
{
	if ($filepath -eq $null)
	{
		throw "路径不能为空"
	}
    $results= [System.Collections.ArrayList]::new()
  
	dir -Path $filepath |
	ForEach-Object -Process {
		if ($_.psiscontainer -eq $true)
		{
            $tempobj=@{}
			$length = 0
			dir -Path $_.fullname -Recurse | ForEach-Object{
				$length += $_.Length
			}
			$l = $length/1MB			
            [void]$results.Add(@{name=$_.name;value=$l})
		}
	}
    
    $r=$results |Sort-Object -Property @{e={$_.value}} -Descending |Select-Object -Property @{e={$_.name}},@{e={$_.value}} -First 20
    $r | foreach {
       $values=$_.psobject.Properties
       $values.value[0]+"  {0:n1} MB" -f $values.value[1]
    }
}
filesize -filepath "C:\"
$enddate=date
$enddate-$startdate